#include "Node.h"
#include <cmath>
#include<iostream>

double NumberNode::Calculator() const {
	return num_;
}

BinaryNode::~BinaryNode() {
	delete left_;
	delete right_;
}

UnaryNode::~UnaryNode() {
	delete child_;
}

double AddNode::Calculator() const {
	return left_->Calculator() + right_->Calculator();
}
double SubNode::Calculator() const {
	return left_->Calculator() - right_->Calculator();
}
double MultiNode::Calculator() const {
	return left_->Calculator() * right_->Calculator();
}
double DivNode::Calculator() const {
	if (right_->Calculator() == 0.0) {
		std::cout << "Divector not allow to zero!" << std::endl;
		return HUGE_VAL;
	}
	return left_->Calculator() / right_->Calculator();
}

double UminusNode::Calculator() const {
	return -child_->Calculator();
}